package icu.qx.gbs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import icu.qx.gbs.domain.GbsGood;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import icu.qx.gbs.domain.GbsBomMaterial;
import icu.qx.gbs.service.IGbsBomMaterialService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物料配件Controller
 *
 * @author yong
 * @date 2024-06-21
 */
@RestController
@RequestMapping("/gbs/bomMaterial")
public class GbsBomMaterialController extends BaseController {
    @Autowired
    private IGbsBomMaterialService gbsBomMaterialService;

    /**
     * 查询物料配件列表
     */
    @GetMapping("/list")
    public R<List<GbsBomMaterial>> list(GbsBomMaterial gbsBomMaterial) {
        List<GbsBomMaterial> list = gbsBomMaterialService.selectGbsBomMaterialList(gbsBomMaterial);
        return R.ok(list);
    }

    /**
     * 获取物料配件详细信息
     */
    @GetMapping(value = "/{bmBomCode}")
    public AjaxResult getInfo(@PathVariable("bmBomCode") String bmBomCode) {
        return success(gbsBomMaterialService.selectGbsBomMaterialByBmBomCode(bmBomCode));
    }

    /**
     * 新增物料配件
     */
    @Log(title = "物料配件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GbsBomMaterial gbsBomMaterial) {
        return toAjax(gbsBomMaterialService.insertGbsBomMaterial(gbsBomMaterial));
    }

    /**
     * 修改物料配件
     */
    @Log(title = "物料配件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GbsBomMaterial gbsBomMaterial) {
        return toAjax(gbsBomMaterialService.updateGbsBomMaterial(gbsBomMaterial));
    }

    /**
     * 删除物料配件
     */
    @Log(title = "物料配件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bmBomCodes}")
    public AjaxResult remove(@PathVariable String[] bmBomCodes) {
        return toAjax(gbsBomMaterialService.deleteGbsBomMaterialByBmBomCodes(bmBomCodes));
    }
}
